package com.techwells.learningkites.base;

import android.app.Application;
import android.content.Context;

import com.techwells.learningkites.database.DaoMaster;
import com.techwells.learningkites.database.DaoMaster.OpenHelper;
import com.techwells.learningkites.database.DaoSession;
import com.techwells.taco.mvvm.ViewModelManager;


public class KitesApplication extends Application {
	
	private static DaoMaster daoMaster;  
    private static DaoSession daoSession;

	@Override
	public void onCreate() {
		super.onCreate();
		initMVVM();
		
	}
	
	
	/**
	 * 初始化框架
	 */
	public void initMVVM() {
		ViewModelManager.manager().addViewModelPlist(ViewModelPlist.hashMap);
	}

	
	/** 
     * 取得DaoMaster 
     *  
     * @param context 
     * @return 
     */  
    public static DaoMaster getDaoMaster(Context context) {  
        if (daoMaster == null) {  
            OpenHelper helper = new DaoMaster.DevOpenHelper(context,"learningkites-db", null);  
            daoMaster = new DaoMaster(helper.getWritableDatabase());  
        }  
        return daoMaster;  
    }  
      
    /** 
     * 取得DaoSession 
     *  
     * @param context 
     * @return 
     */  
    public static DaoSession getDaoSession(Context context) {  
        if (daoSession == null) {  
            if (daoMaster == null) {  
                daoMaster = getDaoMaster(context);  
            }  
            daoSession = daoMaster.newSession();  
        }  
        return daoSession;  
    }  

}
